﻿using Sdcb.PaddleDetection;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AICommon.Paddle.Detection
{
    public static class StuAction
    {

        public static PaddleDetector detector;
        static StuAction()
        {
        }

        public static void testc(string file)
        {
            var mat = OpenCvSharp.Mat.FromImageData(File.ReadAllBytes(file));

            detector = new PaddleDetector(@"models\action\", @"models\action\infer_cfg.yml");
            var result = detector.Run(mat);
            var bitmap = SKBitmap.Decode(file);
            var surface = new SKCanvas(bitmap);
            foreach (var r in result)
            {
                if (r.Confidence < 0.4)
                    continue;
                surface.DrawRect(new SKRect(r.Rect.X, r.Rect.Y, r.Rect.X + r.Rect.Width, r.Rect.Y + r.Rect.Height), new SKPaint() { Style=SKPaintStyle.Stroke, StrokeWidth=1, Color=SKColors.Red});
                surface.DrawText(r.LabelName,r.Rect.X,r.Rect.Y,new SKPaint() { Color=SKColors.White });
            }
            File.Delete("temp.jpg");
            var fs = File.Create("temp.jpg");
            bitmap.Encode(SKEncodedImageFormat.Jpeg, 100).SaveTo(fs);
            fs.Flush();
        }
    }
}
